<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- html 画布 -->
    <canvas id="demo"></canvas>
    <script>
    // function initCanvas() {
        
    //     let canvas = document.querySelector('#demo')
    //     let gd = canvas.getContext('2d') // 二维绘图
    //     let img = new Image();
    //     img.src="https://tse1-mm.cn.bing.net/th/id/R-C.6a05466fd44c43e477de3b1d6a54b387?rik=WUnf2w12tQeVLw&riu=http%3a%2f%2fwww.ukutu.cn%2fupload%2f201510%2f05%2f20151005114406396.jpg&ehk=52XmnkQPviLWMWm7bF4sq4VX26tLxJRHWbipr55fQLw%3d&risl=&pid=ImgRaw&r=0"
    //     img.onload = function() {
    //         gd.drawImage(img, 0, 0)
    //     }
    //     canvas.onclick = function() {
    //         console.log('666')
    //     }
    // } 
    let canvas = document.querySelector('#demo')
    let gd = canvas.getContext('2d') // 二维绘图
    function initCanvas() {
        // img 局部变量 
        let img = new Image();
        img.src="https://tse1-mm.cn.bing.net/th/id/R-C.6a05466fd44c43e477de3b1d6a54b387?rik=WUnf2w12tQeVLw&riu=http%3a%2f%2fwww.ukutu.cn%2fupload%2f201510%2f05%2f20151005114406396.jpg&ehk=52XmnkQPviLWMWm7bF4sq4VX26tLxJRHWbipr55fQLw%3d&risl=&pid=ImgRaw&r=0"
        img.onload = function() {
            gd.drawImage(img, 0, 0)
        }
        // 内部没有子函数
    }
    function initEvent() {
        canvas.onload = function() {
            
        }
    }
    // 调用前
    initCanvas();  // 插入执行栈
    // 出栈  函数变量check一下 没有人要用就垃圾回收
    </script>
</body>
</html>